package cn.hs.servlet;

import cn.hs.dao.CourierstationDao;
import cn.hs.dao.impl.CourierstationDaoImpl;
import cn.hs.entity.Courierstation;
import cn.hs.util.Result;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/courierStation")
public class CourierstationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");
        if ("querySearchCourierStationList".equals(action)){
            Map<String,String> map = new HashMap<>();
            String communityName = req.getParameter("communityName");
            String courierStationName = req.getParameter("courierStationName");
            String courierStationStatus = req.getParameter("courierStationStatus");
            String startTime = req.getParameter("startTime");
            String endTime = req.getParameter("endTime");
            String pageNum = req.getParameter("pageNum");
            String pageSize = req.getParameter("pageSize");
            map.put("communityName",communityName);
            map.put("courierStationName",courierStationName);
            map.put("courierStationStatus",courierStationStatus);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            map.put("pageNum",pageNum);
            map.put("pageSize",pageSize);
            //连接数据库查询
            CourierstationDao courierstationDao = new CourierstationDaoImpl();
            List<Courierstation> list = courierstationDao.selectCourierstations(map);
            int total = courierstationDao.selectCourierstationCount(map);
            Map resultMap = new HashMap();
            resultMap.put("list",list);
            resultMap.put("total",total);
            //把结果集合，封装到result对象中
            Result success = Result.success(resultMap);
            resp.getWriter().write(JSON.toJSONString(success));
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
